package com.first.nell.utils.analytics.util

import android.app.Application
import com.first.nell.ProjectConfig
import com.first.nell.extend.toFirstNellCombineFirstNellUrlFirstNellPath
import com.first.nell.network.ApiUrl
import com.first.nell.utils.UserStateUtil
import com.zhi.syc.data.ASBuilder
import com.zhi.syc.data.ASSycManager
//import com.zhi.syc.point.ASPointBuilder
//import com.zhi.syc.point.ASPointSycManager
import java.util.*

object SycDeviceUtil {

    /**
     * 初始化设备信息模块
     *
     * @param context Application
     */
    fun init(context: Application) {
        try {
            ASBuilder.setMock(false)
            ASBuilder.setLog(true)
            ASBuilder.setServerHost(ApiUrl.BASE_URL)
            ASBuilder.setpApl(ApiUrl.NARSCASH_PATH_APPLIST.toFirstNellCombineFirstNellUrlFirstNellPath())
            ASBuilder.setpMag(ApiUrl.NARSCASH_PATH_MESSAGE.toFirstNellCombineFirstNellUrlFirstNellPath())
            ASBuilder.setpDie(ApiUrl.NARSCASH_PATH_DEVICE.toFirstNellCombineFirstNellUrlFirstNellPath())
            ASBuilder.setpBty(ApiUrl.NARSCASH_PATH_BATTERY.toFirstNellCombineFirstNellUrlFirstNellPath())
            ASBuilder.setpHdw(ApiUrl.NARSCASH_PATH_HARDWARE.toFirstNellCombineFirstNellUrlFirstNellPath())
            ASBuilder.setpSto(ApiUrl.NARSCASH_PATH_STORE.toFirstNellCombineFirstNellUrlFirstNellPath())
            ASBuilder.setpNtw(ApiUrl.NARSCASH_PATH_NETWORK.toFirstNellCombineFirstNellUrlFirstNellPath())
            ASBuilder.setAppid(ProjectConfig.NARSCASH_Product)
            ASBuilder.setKeyProduct(ProjectConfig.NARSCASH_Product)
            ASSycManager.getInstance().init(context)

//            ASPointBuilder.URL_SERVER_HOST = ApiUrl.BASE_URL
//            ASPointBuilder.PATH_POINT_RECORD =
//                ApiUrl.NARSCASH_PATH_POINT_RECORD.toFirstNellCombineFirstNellUrlFirstNellPath()
//            ASPointBuilder.KEY_PRODUCT = ProjectConfig.NARSCASH_Product
//            ASPointBuilder.KEY_APPID = ProjectConfig.NARSCASH_Product
//            ASPointBuilder.KEY_VERSION = ProjectConfig.NARSCASH_Version.toString()
//            ASPointSycManager.getInstance().init(context)

        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    /**
     * 保存设备 s2s信息
     */
    fun saveS2SInfo() {
        try {
            if (UserStateUtil.isFirstNellDidFirstNellLogin()) {
                val permissions = ArrayList<String>()
                permissions.add(android.Manifest.permission.READ_PHONE_STATE)
                permissions.add(android.Manifest.permission.READ_SMS)
                ASSycManager.getInstance()
                    .sycDataByPermissions(UserStateUtil.mFirstNellToken, permissions, true)
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }
}